﻿Shader "SongShaderDemo/ContourLine"
{
	Properties
	{
		_MainTex("Texture", 2D) = "white" {}
		_Linewide("Linewide",Range(1,5)) = 1
		_ContourLine("ContourLine",Int) = 10
		_Color("color",Color) = (1,1,1,1)   //颜色，一般用fixed4
				_Color2("color2",Color) = (1,1,1,0)   //颜色，一般用fixed4
	}
		SubShader
		{
			Tags { "RenderType" = "Transparent"  "Queue" = "Transparent"}
			LOD 100

			Pass
			{
				CGPROGRAM
				#pragma vertex vert
				#pragma fragment frag


				#include "UnityCG.cginc"

				struct appdata
				{
					float4 vertex : POSITION;
					float2 uv : TEXCOORD0;
				};

				struct v2f
				{
					float2 uv : TEXCOORD0;
					float4 vertex : SV_POSITION;
				};
				CBUFFER_START(UnityPerMaterial)
				sampler2D _MainTex;
				float4 _MainTex_ST;
				CBUFFER_END
				v2f vert(appdata v)
				{
					v2f o;
					o.vertex = UnityObjectToClipPos(v.vertex);
					o.uv = TRANSFORM_TEX(v.uv, _MainTex);
					return o;
				}

				fixed4 frag(v2f i) : SV_Target
				{
					// sample the texture
					fixed4 col = tex2D(_MainTex, i.uv);
					return col;
				}
				ENDCG
			}
			Pass
			{
						Blend SrcAlpha OneMinusSrcAlpha
				CGPROGRAM
				#pragma vertex vert
				#pragma fragment frag


				#include "UnityCG.cginc"

				struct appdata
				{
					float4 vertex : POSITION;
					float2 uv : TEXCOORD0;
				};

				struct v2f
				{
					float2 uv : TEXCOORD0;
					float4 vertex : SV_POSITION;
					float3 worldPos : TEXCOORD1;
				};
				CBUFFER_START(UnityPerMaterial)
				sampler2D _MainTex;
				float4 _MainTex_ST;
				fixed _Linewide;
				fixed _ContourLine;
				fixed4 _Color;
				fixed4 _Color2;
				CBUFFER_END
				v2f vert(appdata v)
				{
					v2f o;
					o.vertex = UnityObjectToClipPos(v.vertex);
					o.uv = TRANSFORM_TEX(v.uv, _MainTex);
					float3 curWorldpos= mul(unity_ObjectToWorld, v.vertex).xyz;
					/*if (curWorldpos.y%_ContourLine < _Linewide)
					{*/
						o.worldPos = curWorldpos;
					/*}
					else
					{
						o.worldPos = fixed3(0, 0, 0);
					}*/
					
				//	o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
					return o;
				}

				fixed4 frag(v2f i) : SV_Target
				{
					if (i.worldPos.y%_ContourLine < _Linewide || _ContourLine - (i.worldPos.y%_ContourLine) < _Linewide)
		            {
						return _Color;
		            }
					else
					{
						return _Color2;
	                }

				}
				ENDCG
			}
		}
}
